package com.hexacta.hrs.securitygroups;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import org.vectrics.common.db.RecordObject;
import org.vectrics.user.User;

/**
 * Clase que representa un Security Group
 * 
 * @author mtestasecca
 * @author rmilano
 */
public class SecurityGroup implements RecordObject, Serializable {

    private static final long serialVersionUID = 1200785613367304760L;

    /** id. */
    private Long id;

    /** Nombre del Security Group. */
    private String name;

    /** Description del Security Group. */
    private String description;

    /** Permisos del Security Group. */
    private Set<Permission> securityGroupPermissions = new HashSet<Permission>();

    /** Users del Security Group. */
    private Set<User> users = new HashSet<User>();

    /** Indica si el Security Group es de sistema */
    private Boolean ofSystem = Boolean.FALSE;

    /**
     * Usado solo por Hibernate.
     */
    public SecurityGroup() {
    }

    public SecurityGroup(String name, String description, Set<Permission> securityPermissions, Set<User> users) {
        super();
        this.description = description;
        this.name = name;
        this.securityGroupPermissions = securityPermissions;
        this.users = users;
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Set<Permission> getSecurityGroupRoles() {
        return securityGroupPermissions;
    }

    public void setSecurityGroupRoles(final Set<Permission> securityPermissions) {
        this.securityGroupPermissions = securityPermissions;
    }

    public Set<User> getUsers() {
        return users;
    }

    public void setUsers(Set<User> users) {
        this.users = users;
    }

    public Boolean getOfSystem() {
        return ofSystem;
    }

    public Boolean isOfSystem() {
        return ofSystem;
    }

    public void setOfSystem(Boolean ofSystem) {
        this.ofSystem = ofSystem;
    }

    @Override
    public int hashCode() {
        if (this.getId() == null)
            return (0);
        return (this.getId().hashCode());
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof SecurityGroup) {
            SecurityGroup securityGroup = (SecurityGroup) obj;
            if (securityGroup.getId().equals(this.getId())) {
                return true;
            }
        }
        return false;
    }

}
